<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增仪器')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-instrument-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">HostId：</label>
            <div class="col-sm-8">
                <input id="hostId" name="hostId" class="form-control" type="text" maxlength="32" minlength="32" placeholder="请输入32位hostId"
                       onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" oncontextmenu="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">名称：</label>
            <div class="col-sm-8">
                <input id="instName" name="instName" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">生产商名称：</label>
            <div class="col-sm-8">
                <input name="company" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">生产日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="prodData" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">型号：</label>
            <div class="col-sm-8">
                <input name="type" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">样品总数：</label>
            <div class="col-sm-8">
                <input name="sampleTotal" class="form-control" type="number" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">公告：</label>
            <div class="col-sm-8">
                <textarea name="notice" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "system/instrument"
    $("#form-instrument-add").validate({
        focusCleanup: true,
        onkeyup: false,
        rules: {
            instName:{
                minlength: 2,
                maxlength: 20,
                remote: {
                    url: prefix + "/checkInstNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "instName": function () {
                            return $.common.trim($("#instName").val());
                        }
                    }
                }
            },
            hostId: {
                minlength: 32,
                maxlength: 32,
                remote: {
                    url: prefix + "/checkHostIdUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "hostId": function () {
                            return $.common.trim($("#hostId").val());
                        }
                    }
                }
            }

        },
        messages: {
            "instName": {
                remote: "仪器已经存在"
            },
            "hostId": {
                remote: "hostId已存在"
            }
        }
    });

    $("input[name='prodData']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-instrument-add').serialize());
        }
    }
</script>
</body>
</html>